package com.example.zsf.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.zsf.R;
import com.example.zsf.activity.account.LoginActivity;
import com.example.zsf.base.ZSFGlobal;
import com.example.zsf.model.MobileDetailModel;
import com.example.zsf.utils.DebouncedOnClickListener;
import com.example.zsf.view.CollectedInfoDialog;

import java.util.List;

public class MobileDetailListAdapter extends BaseQuickAdapter<MobileDetailModel.MobileDetailCollectedRecordModel,
        BaseViewHolder> {

    private final Context context;

    public MobileDetailListAdapter(Context context, int layoutResId, List<MobileDetailModel.MobileDetailCollectedRecordModel> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, MobileDetailModel.MobileDetailCollectedRecordModel mobileDetailCollectedRecordModel) {
        baseViewHolder.setText(R.id.textView49, mobileDetailCollectedRecordModel.getRcv_open_name());
        baseViewHolder.setText(R.id.textView53, mobileDetailCollectedRecordModel.getRcv_game_name());//account
        baseViewHolder.setText(R.id.textView48, mobileDetailCollectedRecordModel.getRcv_price() + "元");//price
        baseViewHolder.setText(R.id.textView52, mobileDetailCollectedRecordModel.getRcv_time());//time

        //status
        TextView view = baseViewHolder.getView(R.id.textView51);
        int status = Integer.parseInt(mobileDetailCollectedRecordModel.getRcv_status());
        switch (status) {
            case 0:
                view.setText("待充值");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_title_orange));
                break;
            case 1:
                view.setText("已充值");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_title_green));
                break;
            case 2:
                view.setText("异常");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_mark_red));
                break;
            case 3:
                view.setText("已退回");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_mark_red));
                break;
            case 4:
                view.setText("待填写");
                view.setBackground(context.getResources().getDrawable(R.drawable.bg_title_green));
                break;
        }


        if (baseViewHolder.getAdapterPosition() % 2 == 1) {
            baseViewHolder.getView(R.id.container).setBackgroundColor(context.getResources().getColor(R.color.colordedede));
        } else {
            baseViewHolder.getView(R.id.container).setBackgroundColor(context.getResources().getColor(R.color.colorWhite));
        }


        baseViewHolder.getView(R.id.textView50).setOnClickListener(new DebouncedOnClickListener(400) {
            @Override
            public void onDebouncedClick(View v) {
                if (!ZSFGlobal.checkLogoutStatus(new ZSFGlobal.AccountCallBack() {
                    @Override
                    public void noneauth() {
                        Intent intent = new Intent(context, LoginActivity.class);
                        context.startActivity(intent);
                    }
                })) {
                    CollectedInfoDialog dialog = new CollectedInfoDialog(context,mobileDetailCollectedRecordModel,null);
                    dialog.show();
                }
            }
        });
    }
}
